{% extends 'base/base_table.html' %}

{% block title %}ITAdmin | IDC{% endblock %}

{% block other %}
<div class="ibox-content m-b-sm border-bottom">
    <div class="row">
        <form action="{{ request.path }}">
        <div class="col-sm-4">
            <div class="form-group">
                <label class="control-label" for="date_added">开始时间</label>
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span><input id="date_added" name="start" type="text" class="form-control" value="{{ start }}">
                </div>
            </div>
        </div>
        <div class="col-sm-4">
            <div class="form-group">
                <label class="control-label" for="date_modified">结束时间</label>
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span><input id="date_modified" name="end" type="text" class="form-control" value="{{ end }}">
                </div>
            </div>
        </div>
        <div class="col-sm-1">
            <div class="form-group">
                <label class="control-label" for="date_modified">时间过滤</label>
                <input type="hidden" value="{{ last_search }}" name="top-search">
                <button class="form-control" type="submit"><strong>确定</strong></button>
            </div>
        </div>
        </form>
    </div>
</div>
{% endblock %}

{% block table_btn %}
    <button class="btn btn-sm btn-primary" id="download"><strong>导出EXCEL</strong></button>
{% endblock %}

{% block table_thead %}
    <tr>
        <th>机房名</th>
        <th>地址</th>
        <th>联系电话</th>
        <th>服务器</th>
        <th>服务器总数</th>
    </tr>
{% endblock %}

{% block table_bady %}
    {% for object in objects %}
        <tr>
            <td>
                <a href="#">
                     <span class="label label-sm label-success">{{ object.name }}</span>
                </a>
            </td>
            <td>{{ object.address}}</td>
            <td>{{ object.phone_num }}</td>
            <td>{{ object.get_servers }}</td>
            <td>{{ object.servers.all.count }}</td>
        </tr>
    {% endfor %}
{% endblock %}

{% block script %}
<script type="text/javascript">

    $(function () {
        $('#pages').val('{{ entry }}')
        $("a[id^='server_']").click(function () {
            $.post("{% url 'getserver_info' %}", {id:$(this).attr("value")}, function (data) {
                 swal("密码查看", "ROOT密码：" + data.password + '\n' + "MySQL密码：" + data.mysqlpwd);
                //alert(data.password)
            });
        });
        $('#download').click(function () {
            $.post("{% url 'room' %}", {
                search:$('#top-search').attr('value'),
                start:$('#start').attr('value'),
                end:$("#end").attr('value')},
                function (data) {
                window.open(data.url);
            });
        });
        $('#pages').change(function () {
            var search = '{{ search }}'
            if (search == '') {
                location.href = "{% url 'room' %}?page={{ num }}&entry=" + $(this).val();
            } else {
                location.href = "{% url 'room' %}?page={{ num }}&{{ search }}&entry=" + $(this).val();
            }
        });
    });
</script>
{% endblock %}